package com.fast.alden.admin.web.controller.system;

import com.fast.alden.admin.service.SysMessageService;
import com.fast.alden.data.model.SysMessage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Nullable;
import jakarta.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

@Tag(name = "SysMessageController", description = "消息管理")
@RestController
@RequestMapping("/message")
public class SysMessageController {
    @Resource
    private SysMessageService messageService;

    @Operation(summary = "分页查询", security = @SecurityRequirement(name = "openApiSecurityScheme"))
    @PostMapping("/page")
    public Page<SysMessage> page(@RequestBody @Nullable SysMessage searchVo,
                                 @RequestParam(name = "no", defaultValue = "0") int no,
                                 @RequestParam(name = "size", defaultValue = "10") int size
    ) {
        return messageService.search(searchVo, PageRequest.of(no, size, Sort.by(Sort.Direction.DESC, "createdTime")));
    }

    @Operation(summary = "根据ID查询", security = @SecurityRequirement(name = "openApiSecurityScheme"))
    @GetMapping("/retrieve/{id}")
    public SysMessage retrieve(@PathVariable("id") Long id) {
        return messageService.retrieve(id);
    }
}
